package com.example.user.web;

import com.example.user.web.feign.IIndexAction;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.xml.crypto.Data;

@RestController
public class UserAction {
    @RequestMapping("user")
    public String index(HttpServletRequest request){
        return "index : "+ request.getServerPort();
    }
    @Resource
    RestTemplate restTemplate;
    @RequestMapping("index")
    public String index(){
        String ret = restTemplate.getForObject("http://index/index", String.class);
        return "远程访问index:"+ret;
    }
    @Resource
    IIndexAction indexAction;
    @RequestMapping("indexByFeign")
    public String index1(){
        return indexAction.index();
    }

    @RequestMapping("hello")
    String hello(String name) {
        return "hello"+name;
    }

    @RequestMapping("add")
    int add(int a,int b) {
        return a+b;
    }

    @RequestMapping("reg")
    public User reg(@RequestBody User user){
        user.setName(user.getName()+"xxx");
        return user;
    }
    @RequestMapping("path/{ptest}")
    public String ptest(@PathVariable("ptest") String ptest){
        return ptest+"demo";
    }
}
@lombok.Data
@AllArgsConstructor
class User {
    private String name;
    private int age;
    private Data birthday;
    private String[] likes;
}
